package com.jerry.netty.channel;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

public class Channel04 {
    public static void main(String[] args) throws Exception {
        //创建文件输入流和输入流通道
        FileInputStream fileInputStream = new FileInputStream("img_source.jpg");
        FileChannel inputChannel = fileInputStream.getChannel();

        //创建文件输出流和输出流通道
        FileOutputStream fileOutputStream = new FileOutputStream("img_target.jpg");
        FileChannel outputChannel = fileOutputStream.getChannel();

        //使用transferForm完成copy
        outputChannel.transferFrom(inputChannel,0,inputChannel.size());

        //关闭流
        fileInputStream.close();
        fileOutputStream.close();
    }
}
